<template>
  <div>
    <!-- 头部面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <!-- 搜索框 -->
      <div class="topbox">
        <el-input placeholder="请输入内容" clearable>
          <el-button
            class="btn"
            slot="append"
            icon="el-icon-search"
          ></el-button>
        </el-input>
      </div>
      <el-table :data="orderlist" border stripe="" style="width: 100%">
        <el-table-column type="index"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="180">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="180">
        </el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template v-slot="scope">
            <el-tag type="success" v-if="scope.row.pay_status == 1"
              >已付款</el-tag
            >
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"> </el-table-column>
        <el-table-column prop="create_time" label="发货时间">
          <template v-slot="scope">
            {{ scope.row.create_time | timefilter }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200px">
          <template v-slot="">
            <el-tooltip
              class="item"
              effect="dark"
              content="修改订单地址"
              placement="top-start"
            >
              <el-button
                type="primary"
                size="mini"
                icon="el-icon-thumb"
                @click="showdali()"
                >编辑</el-button
              >
            </el-tooltip>
            <el-tooltip
              class="item"
              effect="dark"
              content="查看物流信息"
              placement="top-start"
            >
              <el-button
                type="success"
                size="mini"
                icon="el-icon-location"
                @click="showordersent"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryinfo.pagenum"
        :page-sizes="[6, 7, 8, 9]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 编辑对话框 -->
    <el-dialog
      title="提示"
      :visible.sync="setisbloack"
      width="30%"
      @close="closcdial"
    >
      <el-form
        :model="setaddfrom"
        :rules="setaddfromrules"
        ref="setaddfrom"
        label-width="100px"
      >
        <el-form-item label="省市区/县" prop="bigaddress">
          <el-cascader
            size="large"
            :options="options"
            v-model="selectedOptions"
            @change="handleChange"
          >
          </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="smaddress">
          <el-input v-model="setaddfrom.smaddress"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="setisbloack = false">取 消</el-button>
        <el-button type="primary" @click="setisbloack = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 查看物流对话框 -->
    <el-dialog title="物流进度" :visible.sync="lookordersend" width="30%">
      <!-- 时间线 -->
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in wuliudata"
          :key="index"
          :timestamp="activity.time"
        >
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <el-button @click="lookordersend = false">取 消</el-button>
        <el-button type="primary" @click="lookordersend = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
//导入省市县数据
import { regionData } from "element-china-area-data";

export default {
  data() {
    return {
      //请求数据
      queryinfo: {
        query: "",
        pagenum: 2,
        pagesize: 6,
      },
      //总条数
      total: 0,
      //订单信息列表
      orderlist: [],
      setisbloack: false,
      setaddfrom: {
        bigaddress: [],
        smaddress: "",
      },
      setaddfromrules: {
        bigaddress: [
          { required: true, message: "请选择省市/县", trigger: "blur" },
        ],
        smaddress: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
        ],
      },
      //级联选择框绑定的数据
      options: regionData,
      //级联选择框选中的数据
      selectedOptions: [],
      //查看物流对话框是否显示
      lookordersend: false,
      //物流数据
      wuliudata: [],
    };
  },
  created() {
    this.getorderlist();
  },
  methods: {
    async getorderlist() {
      const { data: res } = await this.$http.get("/orders", {
        params: this.queryinfo,
      });
      if (res.meta.status !== 200)
        return this.$message.error("获取订单列表失败");
      this.orderlist = res.data.goods;
      this.total = res.data.total;
      this.$message.success("获取订单列表成功");
    },
    //pageseiz改变后执行
    handleSizeChange(nsize) {
      this.queryinfo.pagesize = nsize;
      this.getorderlist();
    },
    //pagenum改编后执行
    handleCurrentChange(num) {
      this.queryinfo.pagenum = num;
      this.getorderlist();
    },
    //修改地址按钮
    showdali() {
      this.setisbloack = true;
    },
    //级联选择器选择的数据改变后执行
    handleChange(value) {
      console.log(value);
    },
    //清空修改地址对话框
    closcdial() {
      this.$refs.setaddfrom.resetFields();
      this.selectedOptions = [];
    },
    //查看物流对话框
    async showordersent() {
      const wldata = {
        data: [
          {
            time: "2018-05-10 09:39:00",
            ftime: "2018-05-10 09:39:00",
            context: "已签收,感谢使用顺丰,期待再次为您服务",
            location: "",
          },
          {
            time: "2018-05-10 08:23:00",
            ftime: "2018-05-10 08:23:00",
            context:
              "[北京市]北京海淀育新小区营业点派件员 顺丰速运 95338正在为您派件",
            location: "",
          },
          {
            time: "2018-05-10 07:32:00",
            ftime: "2018-05-10 07:32:00",
            context: "快件到达 [北京海淀育新小区营业点]",
            location: "",
          },
          {
            time: "2018-05-10 02:03:00",
            ftime: "2018-05-10 02:03:00",
            context:
              "快件在[北京顺义集散中心]已装车,准备发往 [北京海淀育新小区营业点]",
            location: "",
          },
          {
            time: "2018-05-09 23:05:00",
            ftime: "2018-05-09 23:05:00",
            context: "快件到达 [北京顺义集散中心]",
            location: "",
          },
          {
            time: "2018-05-09 21:21:00",
            ftime: "2018-05-09 21:21:00",
            context: "快件在[北京宝胜营业点]已装车,准备发往 [北京顺义集散中心]",
            location: "",
          },
          {
            time: "2018-05-09 13:07:00",
            ftime: "2018-05-09 13:07:00",
            context: "顺丰速运 已收取快件",
            location: "",
          },
          {
            time: "2018-05-09 12:25:03",
            ftime: "2018-05-09 12:25:03",
            context: "卖家发货",
            location: "",
          },
          {
            time: "2018-05-09 12:22:24",
            ftime: "2018-05-09 12:22:24",
            context: "您的订单将由HLA（北京海淀区清河中街店）门店安排发货。",
            location: "",
          },
          {
            time: "2018-05-08 21:36:04",
            ftime: "2018-05-08 21:36:04",
            context: "商品已经下单",
            location: "",
          },
        ],
        meta: { status: 200, message: "获取物流信息成功！" },
      };
      this.wuliudata = wldata.data;
      this.lookordersend = true;
      console.log(this.wuliudata);
    },
  },
};
</script>

<style scoped>
.topbox {
  width: 450px;
  display: flex;
  justify-content: space-between;
}
.btn {
  width: 70px;
}
.addgoods {
  margin: 0 30px;
}
.el-card {
  margin: 10px 0;
}
</style>